package com.example.springboot.config.postProcessor.resolveBeforeInstantiation;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Author:ChenZhangKun
 * @Date: 2023/7/31 18:21
 */
@Component
public class MyInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {
    /**
     * 先于普通的PostProcessor执行，可以在这儿对对象进行改造
     * 返回不为null时，不会执行后面的doCreateBean方法
     *
     * @Override
     * protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
     * 		throws BeanCreationException {
     * 	//...
     * 	try {
     * 		// Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.
     * 		Object bean = resolveBeforeInstantiation(beanName, mbdToUse);
     * 		if (bean != null) {
     * 			return bean;
     *                }    * 	}
     * 	try {
     * 		Object beanInstance = doCreateBean(beanName, mbdToUse, args);
     * 		return beanInstance;
     * 	}
     * 	//...
     * }
     * @param beanClass
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        System.out.println("====postProcessBeforeInstantiation===执行了");
        return null;
    }




    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return null;
    }
}
